package com.blue.fish.tiny.parser.util;

import com.blue.fish.tiny.common.PeekIterator;
import com.blue.fish.tiny.lexer.Token;
import com.blue.fish.tiny.lexer.TokenType;
import com.blue.fish.tiny.parser.util.ParseException;

import java.util.stream.Stream;

/**
 * @author QingFan
 * @version 1.0.0
 * @date 2023年02月01日 21:19
 */
public class PeekTokenIterator extends PeekIterator<Token> {

    public PeekTokenIterator(Stream<Token> stream) {
        super(stream);
    }

    public Token nextMatch(String value) throws ParseException {
        Token token = this.next();
        if (!token.getValue().equals(value)) {
            throw new ParseException(token);
        }
        return token;
    }

    public Token nextMatch(TokenType type) throws ParseException {
        Token token = this.next();
        if (!token.getType().equals(type)) {
            throw new ParseException(token);
        }
        return token;
    }

}
